﻿using System;
using System.Data;

using SqlHelperForCry.Common;

namespace Torch.WL.Entity
{
    [Table("Tb_Company", "companyId", "Torch.WL.ConnectionString")]
    public class Tb_Company : Info
    {
        #region SQL column name consts
        public const string SQLCOL_COMPANYID = "companyId";
        public const string SQLCOL_COMPANYLOGO = "companyLogo";
        public const string SQLCOL_ZHANWEIH = "ZhanWeiH";
        public const string SQLCOL_LOCATION = "location";
        public const string SQLCOL_COMPANYNAME = "companyName";
        public const string SQLCOL_COMPANYTELE = "companyTele";
        public const string SQLCOL_COMPANYMEMO = "companyMemo";
        public const string SQLCOL_PRODUCT = "product";
        public const string SQLCOL_FIRSTPINGYINCHAR = "firstPingYinChar";
        public const string SQLCOL_CREATETIME = "createTime";
        #endregion


        #region Contructors
        /// <summary>
        /// Construct empty entity
        /// </summary>
        public Tb_Company() { }

        /// <summary>
        /// Construct entity by primary key, other fields will be assigned by 
        /// "Load" method.
        /// </summary>
        public Tb_Company(int companyId)
        {
            this.companyId = companyId;
        }
        #endregion

        public override void Init(DataRow row)
        {
            companyId = (int)ObjectType.IntTypeHelper.Read(row[SQLCOL_COMPANYID]);
            companyLogo = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_COMPANYLOGO]);
            ZhanWeiH = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_ZHANWEIH]);
            location = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_LOCATION]);
            companyName = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_COMPANYNAME]);
            companyTele = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_COMPANYTELE]);
            companyMemo = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_COMPANYMEMO]);
            product = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_PRODUCT]);
            firstPingYinChar = (string)ObjectType.StringTypeHelper.Read(row[SQLCOL_FIRSTPINGYINCHAR]);
            createTime = (DateTime)ObjectType.DateTimeTypeHelper.Read(row[SQLCOL_CREATETIME]);
        }

        #region Properties
        #region Property <int> companyId
        [Property("companyId", 4, SqlDbType.Int, true, true)]
        public int companyId
        {
            get { return _companyId; }
            set { _companyId = value; }
        }
        private int _companyId = int.MinValue;
        #endregion

        #region Property <string> companyLogo
        [Property("companyLogo", 100, SqlDbType.VarChar, false, false)]
        public string companyLogo
        {
            get { return _companyLogo; }
            set { _companyLogo = value; }
        }
        private string _companyLogo = null;
        #endregion

        #region Property <string> ZhanWeiH
        [Property("ZhanWeiH", 20, SqlDbType.VarChar, false, false)]
        public string ZhanWeiH
        {
            get { return _ZhanWeiH; }
            set { _ZhanWeiH = value; }
        }
        private string _ZhanWeiH = null;
        #endregion

        #region Property <string> location
        [Property("location", 10, SqlDbType.VarChar, false, false)]
        public string location
        {
            get { return _location; }
            set { _location = value; }
        }
        private string _location = null;
        #endregion

        #region Property <string> companyName
        [Property("companyName", 100, SqlDbType.VarChar, false, false)]
        public string companyName
        {
            get { return _companyName; }
            set { _companyName = value; }
        }
        private string _companyName = null;
        #endregion

        #region Property <string> companyTele
        [Property("companyTele", 100, SqlDbType.VarChar, false, false)]
        public string companyTele
        {
            get { return _companyTele; }
            set { _companyTele = value; }
        }
        private string _companyTele = null;
        #endregion

        #region Property <string> companyMemo
        [Property("companyMemo", 2147483647, SqlDbType.Text, false, false)]
        public string companyMemo
        {
            get { return _companyMemo; }
            set { _companyMemo = value; }
        }
        private string _companyMemo = null;
        #endregion

        #region Property <string> product
        [Property("product", 3000, SqlDbType.VarChar, false, false)]
        public string product
        {
            get { return _product; }
            set { _product = value; }
        }
        private string _product = null;
        #endregion

        #region Property <string> firstPingYinChar
        [Property("firstPingYinChar", 1, SqlDbType.VarChar, false, false)]
        public string firstPingYinChar
        {
            get { return _firstPingYinChar; }
            set { _firstPingYinChar = value; }
        }
        private string _firstPingYinChar = null;
        #endregion

        #region Property <DateTime> createTime
        [Property("createTime", 16, SqlDbType.DateTime, false, false)]
        public DateTime createTime
        {
            get { return _createTime; }
            set { _createTime = value; }
        }
        private DateTime _createTime = DateTime.MinValue;
        #endregion
        #endregion


        public bool LoadByIdentity(int companyId)
        {
            return DataAccess.SelectByIdentity(this, Convert.ToInt64(companyId));
        }


        public bool DeleteByIdentity()
        {
            return DataAccess.DeleteByIdentity(this);
        }
    }
}
